'use strict';

const Service = require('../core/common');

class GoodsIntegralsService extends Service {
  findAll() {
    const { ctx } = this;

    const { goodsId } = ctx.params;

    const { openId, nickname, goodsPrizesId } = ctx.request.query;

    const where = {};
    openId && Object.assign(where, { openId });
    nickname && Object.assign(where, { nickname: { '$like': `%${nickname}%` } });

    return ctx.model.Users.findAndCountAll({
      include: [{
        attributes: [],
        model: ctx.model.Goods,
        where: { id: goodsId },
        through: {
          attributes: [],
          where: { goodsId },
        },
      }],
      order: [
        ['number', 'DESC']
      ],
      ...this.paging({ where }),
    });

    // return ctx.model.Goods.findAndCountAll({
    //   include: [{
    //     model: ctx.model.IntegralOuts,
    //     where: { id: goodsId },
    //   }],
    //   ...this.paging({ where }),
    // });
  }
}

module.exports = GoodsIntegralsService;